/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachinesystem.impl;

import java.util.Collection;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;
import warmachinesystem.TierBenefit;
import warmachinesystem.TierLevel;
import warmachinesystem.TierLevelType;
import warmachinesystem.TierRequirement;
import warmachinesystem.WarmachineSystemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Tier Level</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachinesystem.impl.TierLevelImpl#getLevel <em>Level</em>}</li>
 *   <li>{@link warmachinesystem.impl.TierLevelImpl#getRequirements <em>Requirements</em>}</li>
 *   <li>{@link warmachinesystem.impl.TierLevelImpl#getBenefits <em>Benefits</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class TierLevelImpl extends EObjectImpl implements TierLevel {
	/**
	 * The default value of the '{@link #getLevel() <em>Level</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLevel()
	 * @generated
	 * @ordered
	 */
	protected static final TierLevelType LEVEL_EDEFAULT = TierLevelType.NO_TIER;

	/**
	 * The cached value of the '{@link #getLevel() <em>Level</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLevel()
	 * @generated
	 * @ordered
	 */
	protected TierLevelType level = LEVEL_EDEFAULT;

	/**
	 * The cached value of the '{@link #getRequirements() <em>Requirements</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRequirements()
	 * @generated
	 * @ordered
	 */
	protected EList<TierRequirement> requirements;

	/**
	 * The cached value of the '{@link #getBenefits() <em>Benefits</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBenefits()
	 * @generated
	 * @ordered
	 */
	protected EList<TierBenefit> benefits;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TierLevelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachineSystemPackage.Literals.TIER_LEVEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TierLevelType getLevel() {
		return level;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLevel(TierLevelType newLevel) {
		TierLevelType oldLevel = level;
		level = newLevel == null ? LEVEL_EDEFAULT : newLevel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.TIER_LEVEL__LEVEL, oldLevel, level));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<TierBenefit> getBenefits() {
		if (benefits == null) {
			benefits = new EObjectContainmentEList<TierBenefit>(TierBenefit.class, this, WarmachineSystemPackage.TIER_LEVEL__BENEFITS);
		}
		return benefits;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS:
				return ((InternalEList<?>)getRequirements()).basicRemove(otherEnd, msgs);
			case WarmachineSystemPackage.TIER_LEVEL__BENEFITS:
				return ((InternalEList<?>)getBenefits()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<TierRequirement> getRequirements() {
		if (requirements == null) {
			requirements = new EObjectContainmentEList<TierRequirement>(TierRequirement.class, this, WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS);
		}
		return requirements;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachineSystemPackage.TIER_LEVEL__LEVEL:
				return getLevel();
			case WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS:
				return getRequirements();
			case WarmachineSystemPackage.TIER_LEVEL__BENEFITS:
				return getBenefits();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachineSystemPackage.TIER_LEVEL__LEVEL:
				setLevel((TierLevelType)newValue);
				return;
			case WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS:
				getRequirements().clear();
				getRequirements().addAll((Collection<? extends TierRequirement>)newValue);
				return;
			case WarmachineSystemPackage.TIER_LEVEL__BENEFITS:
				getBenefits().clear();
				getBenefits().addAll((Collection<? extends TierBenefit>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.TIER_LEVEL__LEVEL:
				setLevel(LEVEL_EDEFAULT);
				return;
			case WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS:
				getRequirements().clear();
				return;
			case WarmachineSystemPackage.TIER_LEVEL__BENEFITS:
				getBenefits().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.TIER_LEVEL__LEVEL:
				return level != LEVEL_EDEFAULT;
			case WarmachineSystemPackage.TIER_LEVEL__REQUIREMENTS:
				return requirements != null && !requirements.isEmpty();
			case WarmachineSystemPackage.TIER_LEVEL__BENEFITS:
				return benefits != null && !benefits.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (level: ");
		result.append(level);
		result.append(')');
		return result.toString();
	}

} //TierLevelImpl
